package com.kinon.gfcanteen_v1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kinon.gfcanteen_v1.R;
import com.kinon.gfcanteen_v1.bean.BalanceBean;

import java.util.ArrayList;

/**
 * Created by lhqq on 2018-01-08.
 */

public class RecordAdapter extends BaseAdapter {

    private ArrayList<BalanceBean.Records> list;
    private Context mContext;
    private LayoutInflater inflater;

    public RecordAdapter(ArrayList<BalanceBean.Records> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
        inflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            view= inflater.inflate(R.layout.iten_record_layout,null);
            holder=new ViewHolder();
            holder.tv_recordType=view.findViewById(R.id.tv_recordType);
            holder.recordPrice=view.findViewById(R.id.recordPrice);
            holder.tv_recordDate=view.findViewById(R.id.tv_recordDate);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.tv_recordType.setText("消费");
        holder.recordPrice.setText("￥"+list.get(i).getNum());
        holder.tv_recordDate.setText(list.get(i).getDate());
        return view;
    }

    private class ViewHolder{
        TextView tv_recordType;
        TextView recordPrice;
        TextView tv_recordDate;
    }
}
